package logic

import (
	"context"
	"errors"
	"strings"
	"video-hub/models/mysql"

	"video-hub/videorpc/internal/svc"
	"video-hub/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MenAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMenAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MenAddLogic {
	return &MenAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MenAddLogic) MenAdd(in *videorpc.MenAddRequest) (*videorpc.MenAddResponse, error) {
	// todo: add your logic here and delete this line
	var ment mysql.Comment
	if in.Content == "" {
		return nil, errors.New("请输入评论内容")
	}
	ment = mysql.Comment{
		VideoId: in.VideoId,
		UserId:  in.UserId,
		Content: in.Content,
	}
	if strings.ContainsAny(in.Content, "垃圾,骗人") {
		return nil, errors.New("含违规词汇，请修改")
	}

	if err := ment.AddMen(mysql.DB); err != nil {
		return nil, err
	}
	return &videorpc.MenAddResponse{
		CommentId: int64(ment.ID),
	}, nil
}
